package edu.hawaii.duedates;

import java.util.Collections;
import java.util.List;

/**
 * An abstract representation of a Lender-Borrower relationship which is extended to specify due
 * date data collection depending on Lender criteria and user needs.
 * 
 * @author Aric West
 * @author Daniel Tian
 * 
 */
public abstract class LenderQuery implements Comparable<LenderQuery> {
  protected int expectedNumberOfFields;
  protected String lenderName;
  protected List<BorrowedItem> itemList;
  
  /**
   * Logs into lender website and navigates to page containing due dates.
   * 
   * @param fieldList a List of the fields that the class needs to log into the lender system
   * @return boolean whether the logIn was successful or not
   */
  protected abstract boolean logIn(List<String> fieldList);

  /**
   * Parses the source of information holding borrowed items and due date information.  This is
   * often from a table.
   * 
   * @return True if success, else failure.
   */
  public abstract boolean parseBorrowedItems();

  /**
   * Returns the number of fields this class needs to log into the UH library system.
   * @return the number of fields
   */
  public int getExpectedNumberOfFields() {
    return expectedNumberOfFields;
  }
  
  /**
   * Returns the lender's name.
   * 
   * @return The lender's name.
   */
  public String getLenderName() {
    return lenderName;
  }
  
  /**
   * Returns the list of borrowed items.
   * 
   * @return the list of borrowed items
   */
  public List<BorrowedItem> getItemList() {
    return itemList;
  }
  
  /**
   * Sorts the item list by earliest due date.
   */
  public void sort() {
    Collections.sort(this.itemList);
  }
  
  /**
   * Compares the this LenderQuery object to another to determine order.
   * 
   * @param lq The LenderQuery object being compared to.
   * @return Value of ordering.
   */
  public int compareTo(LenderQuery lq) {
    return this.getLenderName().compareTo(lq.getLenderName());
  }
}